package initialize

import (
	"counter-help/admin/server/global"
	"counter-help/admin/server/plugin/email"
	"counter-help/admin/server/plugin/sms"
	"counter-help/admin/server/plugin/wxlogin"
	"counter-help/admin/server/plugin/wxpay"
	"counter-help/admin/server/utils/plugin"
	"fmt"
	"github.com/gin-gonic/gin"
)

func PluginInit(group *gin.RouterGroup, Plugin ...plugin.Plugin) {
	for i := range Plugin {
		fmt.Println(Plugin[i].RouterPath(), "注册开始!")
		PluginGroup := group.Group(Plugin[i].RouterPath())
		Plugin[i].Register(PluginGroup)
		fmt.Println(Plugin[i].RouterPath(), "注册成功!")
	}
}

func bizPluginV1(group ...*gin.RouterGroup) {
	private := group[0]
	public := group[1]
	//  添加跟角色挂钩权限的插件 示例 本地示例模式于在线仓库模式注意上方的import 可以自行切换 效果相同
	PluginInit(private, email.CreateEmailPlug(
		global.GVA_CONFIG.Email.To,
		global.GVA_CONFIG.Email.From,
		global.GVA_CONFIG.Email.Host,
		global.GVA_CONFIG.Email.Secret,
		global.GVA_CONFIG.Email.Nickname,
		global.GVA_CONFIG.Email.Port,
		global.GVA_CONFIG.Email.IsSSL,
	))

	PluginInit(public, wxpay.CreateWxpayPlug(
		global.GVA_CONFIG.Wxpay.MchID,
		global.GVA_CONFIG.Wxpay.AppID,
		global.GVA_CONFIG.Wxpay.MchCertificateSerialNumber,
		global.GVA_CONFIG.Wxpay.MchAPIv3Key,
		global.GVA_CONFIG.Wxpay.PemPath,
		global.GVA_CONFIG.Wxpay.NotifyUrl,
	))
	// 微信登陆插件
	PluginInit(public, wxlogin.CreateWxLoginPlug(
		"wx010d5cdb13059204",
		"0bbc910ac8040b4d3e7b6c3b3f4c93b4",
		"testbangbang",
		1))
	// 手机号验证插件
	PluginInit(public, sms.CreateAliSmsPlug(
		"LTAI5t7jM83CKzM2pW1nUKb9",
		"klQw4QvaBoq012hESDSXuC4q7ZDMCd",
		"统计帮bangbang"))
	holder(public, private)
}
